/*
 * AqueousPhase.h
 *
 *  Created on: 23 May 2011
 *      Author: allan
 */

#ifndef AQUEOUSPHASE_H_
#define AQUEOUSPHASE_H_

// C++ includes
#include <vector>
using namespace std;

// FluidReact includes
#include "Phase.h"

enum AqueousActivityModel
{
	AQUEOUSACTIVITYMODEL_IDEAL,
	AQUEOUSACTIVITYMODEL_HKF_ION,
	AQUEOUSACTIVITYMODEL_HKF_WATER,
	AQUEOUSACTIVITYMODEL_SETSCHENOW
};

class AqueousPhase : public Phase
{
public:
	AqueousPhase();
	
	virtual ~AqueousPhase();
	
	void AddSpecies(string nameOfSpecies);
	
	void SetElectrolyte(string electrolyte, const vector<pair<string,double>>& ions);
	
	/// It sets the HKF model for the aqueous activity coefficients of water and ionic species.
	void SetActivityCoefficientModelHKF();
	
	/// It sets the Setschenow model for the the aqueous activity coefficients of the species.
	void SetActivityCoefficientModelSetschenow(string nameOfSpecies, double setschenow);
	
	const unsigned GetNumOfIons() const;
	
	const unsigned GetNumOfElectrolytes() const;
	
	const unsigned GetIndexOfWater() const;
	
	const unsigned GetIndexOfIon(unsigned iIon) const;
	
	const unsigned GetIndexOfIon(string nameOfIon) const;
	
	const unsigned GetIndexOfElectrolyte(unsigned iElectrolyte) const;
	
	const unsigned GetIndexOfElectrolyte(string nameOfElectrolyte) const;
	
	const vector<pair<unsigned,double>> GetIonsOfElectrolyte(unsigned iElectrolyte) const;
	
	const int GetElectricalChargeOfSpecies(unsigned iSpecies) const;
	
	const double GetMolalityOfSpecies(unsigned iSpecies) const;
	
	const double GetEffectiveIonicStrength() const;
	
	const double GetStoichiometricIonicStrength() const;
	
	const vector<double> GetStoichiometricMolalityOfIons() const;
	
	const double GetTotalMolalityOfSolutes() const;
	
	const vector<double> ActivityCoefficients(double T, double P) const;
	
	const vector<double> Activities(double T, double P) const;
	
private:
	/// The index of the water species.
	unsigned indexOfWater;
	
	/// The electrical charge of the species.
	vector<int> z;
	
	/// The indexes of the ions in the aqueous phase.
	vector<unsigned> ions;
	
	/// The indexes of the electrolytes in the aqueous phase.
	vector<unsigned> electrolytes;
	
	/// The ion index of each species. If the species is not an ion, its ion index is unsigned(-1) 
	vector<unsigned> species2ions;
	
	/// The indexes and stoichiometries of the ions of each electrolyte in the aqueous phase.
	vector<vector<pair<unsigned,double>>> ionsOfElectrolytes;
	
	/// The effective electrostatic radii of the ions used in the HKF activity coefficient model for the ions and water.
	vector<double> effRadii;
	
	/// The Setschenow constants used in the Setschenow activity coefficient model for neutral species. The values for ions and water are ignored.
	vector<double> setschenowConstants;
	
	/// The activity coefficient models of the species.
	vector<AqueousActivityModel> activityModels;
};

#endif /* AQUEOUSPHASE_H_ */
